package com.gs.testip;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

@SpringBootApplication
public class TestIpApplication {

    public static void main(String[] args) {
        SpringApplication.run(TestIpApplication.class, args);


        // 获取当前程序的运行进对象
        Runtime runtime = Runtime.getRuntime();
        //声明处理类对象
        Process process = null;
        //返回行信息
        String line = null;
        //输入流
        InputStream is = null;
        // 字节流
        InputStreamReader isr = null;

        BufferedReader br = null;

        String ip = "www.baidu.com";
        String cmd1 = "arp -a";
        String cmd2 = "netsh interface ip set address  \"以太网\" static  192.168.2.3 255.255.255.0 192.168.2.1";
        try {
            process =   runtime.exec(cmd2);
//            process = runtime.exec(cmd1);
            // 实例化输入流
            is = process.getInputStream();
            // 把输入流转换成字节流
            isr = new InputStreamReader(is);
            // 从字节中读取文本
            br = new BufferedReader(isr);

            while ((line = br.readLine()) != null) {
                System.out.println( new String(line.getBytes("GBK"),"UTF-8"));
                System.out.println(  new String(line.getBytes("iso-8859-1") ,"GBK") );
                System.out.println(  new String(line.getBytes("iso-8859-1") ,"UTF-8") );
            }

            is.close();

            isr.close();

            br.close();

        } catch (IOException e) {
            System.out.println(e);
            runtime.exit(1);
        }

    }

}
